﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using Model;

namespace BusinessLogic
{
    public class SearchRequestCommand : BaseCommand<List<acm_req>>
    {
        public SearchRequestCommand(string dealerCode,string searchType)
        {
            SetQuery("exec REQUEST_SEARCH @dealerCode,@searchType");

            cmd.Parameters.AddWithValue("dealerCode",dealerCode);
            cmd.Parameters.AddWithValue("searchType",searchType);
        }

        public override void Command()
        {
 	        SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                Result = new List<acm_req>();
                int i = 0;
                while (dr.Read())
                {
                    acm_req req = new acm_req();
                    req.tx_id = dr.GetInt32(0);
                    req.vin = dr.GetString(1);
                    req.dealer_name = GetNullableString(dr, 2);
                    req.change_status = dr.GetString(3);
                    req.RowNumber = ++i;

                    Result.Add(req);
                }
            }

        }
    }
}
